package edu.usc.cmb.iregulome.util;

/**
 * 
 * This class is used for makeup language string process
 * 
 * @author hsy541
 * 
 */
public class MLUtil {

	private static String[] HTML_NOTATION = new String[] { "&lt;", "<", "&gt;",
			">", "&quot;", "\"" };

	private static String[] HTML_TAG = new String[] { "<[/]?div[^>]*>",
			"<[/]?b[^>]*>", "<[/]?span[^>]*>", "<[/]?i[^>]*>" };

	/**
	 * 
	 * This method replace special notation &...; to the exact character
	 * For this version it will convert &lt;  &gt;  &quot; to < > "
	 * 
	 * @param stringTobeProcessed
	 * @return
	 */
	public static String processHtmlNotation(String stringTobeProcessed) {
		if (stringTobeProcessed == null) {
			return null;
		}
		String processedResult = stringTobeProcessed;
		for (int i = 0; i < HTML_NOTATION.length; i++, i++) {
			processedResult = processedResult.replaceAll(HTML_NOTATION[i],
					HTML_NOTATION[i + 1]);
		}
		return processedResult;

	}

	/**
	 * 
	 * 
	 * This method will extract xml string from the html wrapper
	 * @param html
	 * @return
	 */
	public static String extractXMLFromHtml(String html) {
		html = processHtmlNotation(html);
		if (html == null) {
			return null;
		}
		for (String htmlTag : HTML_TAG) {
			html = html.replaceAll(htmlTag, "");
		}
		return html;

	}
}
